<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">

<title>模块管理</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

</head>

<body>
	<%@ include file="/WEB-INF/jsp/common/header.jsp"%>

	<script>
		$(function() {
			loadCombotree();
			bindgrid();
		});
	</script>
	<script>
		function editrow() {
			var node = $('#tt').treegrid('getSelected');
			if (node) {
				//修改
				$('#t1').val(node.moduleid);
				$('#t2').val(unescape(node.modulename));
				$('#t3').combotree('setValue', node.parentmoduleid);
				$('#t4').val(unescape(node.moduleurl));
				$('#t5').val(unescape(node.actionstring));
				$('#t4_1').combobox('setValue', node.mtarget);
				$('#t6').combobox('setValue', node.show);
				$('#ckDisabled').combobox('setValue', node.disabled);
				//if (node.SHOW == "1")
				//    $('#t6').attr("checked", "checked");
				//else
				//    $('#t6').attr('checked', false);
				//if (node.DISABLED == "1")
				//    $('#ckDisabled').attr("checked", "checked");
				//else
				//    $('#ckDisabled').attr('checked', false);

				$('#t8').numberbox('setValue', node.sortby);
				$('#t9').val(unescape(node.mcomment));
				$('#add').window('open');
			} else
				$.messager.alert('消息', '请选中一个节点');
		}

		function del(node) {
			$.ajax({
				type : "post",
				url : "ModuleManage/DelModule",
				//                dataType: "xml",
				data : {
					MODULEID : node.moduleid,
					czr : PUser.userid
				},
				success : function(data) {
					$.messager.alert('消息', data);
					loadCombotree();
					bindgrid();
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					$.messager.alert('消息', errorThrown);
				}
			});
		}
		function save() {
			if (!$('#ssec-form').form('validate')) {
				return;
			}
			var a = $('#t1').val();
			var b = $('#t2').val();
			var c = $('#t3').combotree('getValue');
			var d = $('#t4').val();
			var d_1 = $('#t4_1').combotree('getValue');
			var e = $('#t5').val();
			//var f = $('#t6').prop("checked");
			//var g1 = $('#ckDisabled').prop("checked");
			var f = $('#t6').combobox('getValue');
			var g1 = $('#ckDisabled').combobox('getValue');
			var h = $('#t8').val();
			var i = $('#t9').val();
			//alert($('#ckDisabled').prop("checked"));
			$.ajax({
				type : "post",
				url : "ModuleManage/AddModule",
				//                dataType: "xml",
				data : {
					id : a,
					name : b,
					pid : c,
					murl : d,
					action : e,
					target : d_1,
					show : f,
					disabled1 : g1,
					sortby : h,
					comment : i,
					czr : PUser.userid
				},
				success : function(data) {
					$.messager.alert('消息', data);
					if (data == '保存成功!') {
						$('#add').window('close');
						loadCombotree();
						bindgrid();
					}
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					$.messager.alert('消息', errorThrown);
				}
			});
		}
	</script>
	<script>
		function loadCombotree() {
			$('#t3').combotree({
				url : 'ModuleManage/ModuleListJson_combotree'
			});
		}
		function bindgrid() {
			$('#tt')
					.treegrid(
							{
								title : '系统模块列表',
								url : 'ModuleManage/ModuleListJson_Tree',
								iconCls : 'icon-applicationgo',
								width : 1000,
								nowrap : true,
								rownumbers : true,
								animate : false,
								collapsible : false,
								singleSelect : true,
								remoteSort : false,
								idField : 'moduleid',
								treeField : 'modulename',
								height : 500,
								columns : [ [ {
									field : 'moduleid',
									title : '编码',
									hidden : true,
									width : 50
								}, {
									field : 'modulename',
									title : '名称',
									sortable : true,
									width : 330,
									formatter : function(val, rec) {
										return unescape(val)
									}
								}, {
									field : 'moduleurl',
									title : '地址',
									width : 330,
									formatter : function(val, rec) {
										return unescape(val)
									}
								}, {
									field : 'actionstring',
									title : '权限',
									width : 300,
									formatter : function(val, rec) {
										return unescape(val)
									}
								}, {
									field : 'show',
									title : '显示',
									// 									width : 30,
									formatter : function(val, rec) {
										if (val == '0')
											return '隐藏';
										if (val == '1')
											return '显示';
									}
								}, {
									field : 'disabled',
									title : '启用禁用',
									// 									width : 30,
									formatter : function(val, rec) {
										if (val == "1") {
											return '启用';
										} else {
											return '禁用';
										}
									}
								}, {
									field : 'sortby',
									title : '排序',
									sortable : true,
									width : 30,
									formatter : function(val, rec) {
										return unescape(val)
									}
								}, {
									field : 'mcomment',
									title : '备注',
									// 									width : 40,
									formatter : function(val, rec) {
										return unescape(val)
									}
								},
								//{ field: 'mtarget', title: '备注', width: 40, formatter: function (val, rec) { return unescape(val) } }
								] ],
								toolbar : [
										{
											text : '新增同级节点',
											iconCls : 'icon-add',
											handler : function() {
												$('#ssec-form').form('clear');
												$('#add').window('open');
												var node = $('#tt').treegrid(
														'getSelected');
												if (node != null) {
													//弹出窗口
													$('#t3')
															.combotree(
																	'setValue',
																	node.parentmoduleid);
												}
												$('#t6').combobox("setValue",
														'1');
												$('#ckDisabled').combobox(
														"setValue", '0');
												$('#t5').val('显示，');
												//$('#t4_1').combobox('clear');
												$('#t4_1').combobox('select',
														'mainframe');
											}
										},
										'-',
										{
											text : '增加子节点',
											iconCls : 'icon-add',
											handler : function() {
												$('#ssec-form').form('clear');
												$('#add').window('open');
												var node = $('#tt').treegrid(
														'getSelected');
												if (node != null) {
													//弹出窗口
													$('#t3').combotree(
															'setValue',
															node.moduleid);
												}
												$('#t6').combobox("setValue",
														'1');
												$('#ckDisabled').combobox(
														"setValue", '1');
												$('#t5').val('显示,');
												//$('#t4_1').combobox('clear');
												$('#t4_1').combobox('select',
														'mainframe');
											}
										},
										'-',
										{
											text : '修改节点',
											iconCls : 'icon-edit',
											handler : function() {
												editrow();
											}
										},
										'-',
										{
											text : '删除节点',
											iconCls : 'icon-remove',
											handler : function() {
												var node = $('#tt').treegrid(
														'getSelected');
												var nodes;
												if (node) {
													nodes = $('#tt').treegrid(
															'getChildren',
															node.moduleid);
													if (nodes.length > 0) {
														$.messager
																.alert('消息',
																		'当前节点还有子节点，请先删除子节点！');
														return;
													} else {
														$.messager
																.confirm(
																		'提示',
																		'确定要删除【'
																				+ unescape(node.modulename)
																				+ '】这个模块吗?',
																		function(
																				r) {
																			if (r) {
																				del(node);
																			}
																		});
													}
												} else
													$.messager.alert('消息',
															'请选中一个节点');
											}
										} ],
								onLoadSuccess : function() {
									$('#mask').fadeOut('slow');

								}
							});
		}
	</script>
	<style scoped="scoped">
.textbox {
	height: 20px;
	margin: 0;
	padding: 0 2px;
	box-sizing: content-box;
}

.table tr {
	height: 15px;
}
</style>
	<table id="tt"></table>
	<div id="add" class="easyui-window" closed="true" modal="true"
		title="模块信息" style="width: 600px; height: 500px; padding: 10px 20px">
		<form id="ssec-form" class="ssec-form">
			<table class="table">
				<tr style="display: none;">
					<td>
						<div class="ssec-label" style="display: none;">模块ID：</div>
					</td>
					<td>
						<div class="ssec-text normal" style="display: none;">
							<input id="t1" type="text" />
						</div>
					</td>
				</tr>
				<tr>
					<td>
						<div class="ssec-label">模块名称：</div>
					</td>
					<td>
						<div class="ssec-text large" style="width: 400px;">
							<input id="t2" class="easyui-validatebox textbox"
								data-options="required:true" />
						</div>
					</td>
				</tr>
				<tr>
					<td>
						<div class="ssec-label">上级节点：</div>
					</td>
					<td>
						<div>
							<input id="t3" class="easyui-combotree" style="width: 400px;"
								data-options="required:true" panelheight="300px"
								panelwidth="400px" />
						</div>
					</td>
				</tr>
				<tr>
					<td>
						<div class="ssec-label">访问URL：</div>
					</td>
					<td>
						<div class="ssec-text large">
							<input id="t4" class="easyui-validatebox textbox"
								data-options="required:true" style="width: 400px;" />
						</div>
					</td>
				</tr>
				<tr>
					<td>
						<div class="ssec-label">URL打开方式：</div>
					</td>
					<td>
						<div>
							<select id="t4_1" class="easyui-combobox" style="width: 100px;">
								<option value="mainframe">mainframe</option>
								<option value="_blank">_blank</option>
								<option value="_self">_self</option>
								<option value="_parent">_parent</option>
								<option value="_top">_top</option>
							</select>
						</div>
					</td>
				</tr>
				<tr>
					<td>
						<div class="ssec-label">权限描述：</div>
					</td>
					<td>
						<div class="ssec-text  large" style="float: left;">
							<input id="t5" class="easyui-validatebox textbox"
								data-options="required:true" style="width: 400px;" />
						</div>
					</td>
				</tr>
				<tr>
					<td>
						<div class="ssec-label">显示隐藏：</div>
					</td>
					<td><select id="t6" class="easyui-combobox"
						style="width: 100px;">
							<option value="1">显示</option>
							<option value="0">隐藏</option>
					</select></td>
				</tr>
				<tr>
					<td>
						<div class="ssec-label">是否启用：</div>
					</td>
					<td><select id="ckDisabled" class="easyui-combobox"
						style="width: 100px;">
							<option value="1" checked="true">启用</option>
							<option value="0">禁用</option>
					</select></td>
				</tr>
				<tr>
					<td>
						<div class="ssec-label">排序：</div>
					</td>
					<td>
						<div class="ssec-text normal">
							<input id="t8" class="easyui-numberbox"
								data-options="required:true" />
						</div>
					</td>
				</tr>
				<tr>
					<td>
						<div class="ssec-label">备注描述：</div>
					</td>
					<td>
						<div class="ssec-text normal">
							<input id="t9" class="easyui-validatebox textbox" />
						</div>
					</td>
				</tr>
			</table>
			<div style="text-align: left; padding: 5px">
				<a class="easyui-linkbutton" iconcls="icon-save" onclick="save();">保存</a>
			</div>
		</form>
	</div>
</body>
</html>
